﻿///////////////////////////////////////////////////////
//
// XDesigner.ORM 
//
// autohr : yuans
//
// date: 2011-2-23
//
// email  : yyf9989@hotmail.com
// 
//
///////////////////////////////////////////////////////

using System;
using System.Collections.Generic;
using System.Text;
using XDesigner.ORM.DOM ;

namespace XDesigner.ORM
{
    [AttributeUsage( AttributeTargets.Property )]
    public class ORMRelationAttribute : Attribute 
    {
        public ORMRelationAttribute()
        {
        }

        public ORMRelationAttribute(ORMRelationStyle style)
        {
            this._Style = style;
        }
        public ORMRelationAttribute(ORMRelationStyle style,  string childFieldName)
        {
            this._Style = style;
            this._ChildFieldName = childFieldName;
        }
        

        public ORMRelationAttribute(ORMRelationStyle style, string parentFieldName, string childFieldName)
        {
            this._Style = style;
            this._ParentFieldName = parentFieldName;
            this._ChildFieldName = childFieldName;
        }
        
        private ORMRelationStyle _Style = ORMRelationStyle.Auto;
        /// <summary>
        /// Relation style
        /// </summary>
        public ORMRelationStyle Style
        {
            get { return _Style; }
            set { _Style = value; }
        }

        private string _ParentFieldName = null;
        /// <summary>
        /// Parent field name, default value is type's key property dbfield name.
        /// </summary>
        public string ParentFieldName
        {
            get { return _ParentFieldName; }
            set { _ParentFieldName = value; }
        }

        private string _ChildFieldName = null;
        /// <summary>
        /// Child field name
        /// </summary>
        public string ChildFieldName
        {
            get { return _ChildFieldName; }
            set { _ChildFieldName = value; }
        }

        private bool _LogReference = true;

        public bool LogReference
        {
            get { return _LogReference; }
            set { _LogReference = value; }
        }
         

        //private string _CustomCommandText = null;
        ///// <summary>
        ///// Custom command text for query data
        ///// </summary>
        //public string CustomCommandText
        //{
        //    get 
        //    {
        //        return _CustomCommandText; 
        //    }
        //    set
        //    {
        //        _CustomCommandText = value; 
        //    }
        //}

        private bool _UniteDeleteForDelete = false;
        /// <summary>
        /// When delete parent record , delete all child records
        /// </summary>
        public bool UniteDeleteForDelete
        {
            get { return _UniteDeleteForDelete; }
            set { _UniteDeleteForDelete = value; }
        }

        private bool _UniteDeleteForUpdate = false;
        /// <summary>
        /// When update parent record , delete all child records and insert new child reocords
        /// </summary>
        public bool UniteDeleteForUpdate
        {
            get { return _UniteDeleteForUpdate; }
            set { _UniteDeleteForUpdate = value; }
        }
    }
}
